{include file='head'/}
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">插件标识</label>
                <div class="layui-input-block">
                    <input type="text" lay-verify="required" autocomplete="off" placeholder="请输入插件标识"
                           class="layui-input readonly_bg" readonly="readonly" value="{$config.name}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">扩展信息<br>配置项</label>
                <div class="layui-input-block">
                    <textarea placeholder="扩展信息-配置项" class="layui-textarea"
                              name="extends[title]">{$config.extends.title|default=''}</textarea>
                </div>
            </div>
            <div class="layui-form-item layui-tab">
                <label class="layui-form-label">变量</label>
                <div class="layui-input-block">
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th>变量名</th>
                            <th>变量值</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="params_view">
                        {volist name="config.rewrite" id="vo" key="key"}
                        <tr data-id="{$key-1}">
                            <td>
                                <input type="text" name="rewrite_key[]" value="{$vo.key}" placeholder=""
                                       autocomplete="off" lay-verify="required"
                                       class="layui-input seller-inline-1">
                            </td>
                            <td>
                                <input type="text" name="rewrite_value[]" value="{$vo.value}" placeholder=""
                                       lay-verify="required"  autocomplete="off" class="layui-input seller-inline-1">
                            </td>
                            <td style="width: 110px;">
                                <a class="layui-btn layui-btn-danger layui-btn-xs del-params-class">
                                    删除
                                </a>
                                {if($key==count($config.rewrite))}
                                <a class="layui-btn layui-btn-xs add-params-class">
                                    添加
                                </a>
                                {/if}

                            </td>
                        </tr>
                        {/volist}

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

<script id="params_tpl" type="text/html">
    <tr data-id="{{ d.id }}">
        <td>
            <input type="text" name="rewrite_key[]" required value=""
                   lay-verify="required"
                   placeholder="" autocomplete="off" class="layui-input seller-inline-1">
        </td>
        <td>
            <input type="text" name="rewrite_value[]" value=""
                   placeholder="" autocomplete="off"
                   class="layui-input seller-inline-1">
        </td>
        <td>
            <a class="layui-btn layui-btn-danger layui-btn-xs del-params-class">
                删除
            </a>
        </td>
    </tr>
</script>

{include file='footer'/}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.jquery;
    let laytpl = layui.laytpl;
    form.render();

    $(".layui-tab").on('click', '.add-params-class', function (e) {
      var getTpl = params_tpl.innerHTML;
      var lastId = $(this).parent().parent().parent().find('tr').last().attr('data-id');
      var tmpData = {};
      tmpData.id = parseInt(lastId) + 1;
      laytpl(getTpl).render(tmpData, function (html) {
        $("#params_view").append(html);
      });
      form.render();
    });
    $(".layui-tab").on('click', '.del-type-class,.del-params-class', function (e) {
      $(this).parent().parent().remove();
    })

    form.on('submit(admin-save)', function (data) {

      var jurisdiction={};//创建一个空对象
      /*$('input[name^="rewrite_key"]').each(function(index,element){
        jurisdiction['rewrite_key'][index] = $(this).val();
      });*/

      $.ajax({
        url: "",
        data: data.field,
        dataType: 'json',
        type: 'post',
        success: function (res) {
          if (res.code === 200) {
            hui_msg(res.msg, 1, function () {
              window.location.reload();
            });
          } else {
            hui_msg(res.msg, 2);
          }
        }
      })
      return false;
    });
  })
</script>
<script>
</script>
</body>
</html>
